
function SqlDatabase() {
	var draw = DrawMsg();
	return {
		addMsg: function (email, username, color, msg, me) {
			var sql = openDatabase("mysql", "1", "old messeges", 2*1024*1024);
			sql.transaction(function (context) {
				context.executeSql("create table if not exists oldmsg(email, username, color, msg, me)");
				context.executeSql("insert into oldmsg(email, username, color, msg, me) values " + 
					"('"+ email +"', '" + username + "', '" + color + 
					"', '" + msg + "', '" + me + "')");
			});
		},
		drawMsg: function () {
			var sql = openDatabase("mysql", "1", "old messeges", 2*1024*1024);
			sql.transaction(function (context) {
				context.executeSql("select * from oldmsg", [], function (context, results){
					// console.log(results.rows);
					// l = results.rows.length;
					for (var i = 0; i < results.rows.length; i ++) {
						// r[i] = results.rows[i];
						draw.drawMsg(results.rows[i].username, results.rows[i].color, results.rows[i].msg, results.rows[i].me);
						// console.log(results.rows[i].msg);
					}
					// console.log(l);
				});
			});
		}
	}
}